<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/template/general.xhtml">
	<ui:define name="title">Template reports</ui:define>
	<ui:define name="navigation">
		<h:form id="nav">
			<p:tabMenu activeIndex="2">
				<p:menuitem value="Home" action="home" icon="ui-icon-home" />
				<p:menuitem value="Generate report" action="generate"
					icon="ui-icon-pencil" />
				<p:menuitem value="Report templates" action="template"
					icon="ui-icon-document" />
			</p:tabMenu>
		</h:form>
	</ui:define>

	<ui:define name="content">

		<h:form id="form">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />
			<p:panelGrid>
				<p:row>
					<p:column>
						<h:outputLabel value="Interval:" />
					</p:column>
					<p:column>
						<p:calendar value="#{requsetTemplateBean.fromDate}" id="fromCal">
							<p:ajax update="form" event="dateSelect"
								listener="#{requsetTemplateBean.selectFromDate}" />
						</p:calendar>
					</p:column>
					<p:column>
						<p:calendar value="#{requsetTemplateBean.untilDate}" id="untilCal">
							<p:ajax update="form" event="dateSelect"
								listener="#{requsetTemplateBean.selectUntilDate}" />
						</p:calendar>
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<h:outputLabel value="Report Type:" />
					</p:column>
					<p:column>
						<p:selectOneMenu id="reportType"
							value="#{requsetTemplateBean.selectedReportType}">
							<f:selectItem itemLabel="Report type" itemValue="" />
							<f:selectItems value="#{requsetTemplateBean.reportType}" />
						</p:selectOneMenu>
					</p:column>
					<p:column>
						<p:selectOneMenu id="reportFormat" editable="false"
							value="#{requsetTemplateBean.selectedReportFormat}">
							<f:selectItem itemLabel="Report fromat" itemValue="" />
							<f:selectItems value="#{requsetTemplateBean.reportFormat}" />
						</p:selectOneMenu>
					</p:column>
				</p:row>
				<p:row>
					<p:column colspan="3">
						<p:dataTable var="requestTemplateEntity" paginator="true"
							rows="#{requsetTemplateBean.rowNumber}"
							paginatorTemplate="{PageLinks}"
							value="#{requsetTemplateBean.requestTemplates}"
							rowKey="#{requestTemplateEntity.id}"
							selection="#{requsetTemplateBean.selectedRequestTemplates}"
							selectionMode="single">



							<p:column>
								<h:outputText value="#{requestTemplateEntity.templateName}" />
							</p:column>


						</p:dataTable>
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<p:commandButton update="form" value="Generate"
							actionListener="#{requsetTemplateBean.generateReport}"
							onclick="PrimeFaces.monitorDownload(start, stop)">
							<p:fileDownload contextDisposition="inline"
								value="#{requsetTemplateBean.report}" />
						</p:commandButton>
					</p:column>
					<p:column>
						<p:commandButton update="form" value="Delete"
							actionListener="#{requsetTemplateBean.deleteTemplate}" />
					</p:column>
				</p:row>
			</p:panelGrid>
		</h:form>
		<f:metadata>
			<f:event type="preRenderView"
				listener="#{requsetTemplateBean.getAllRequestTemplates}" />
		</f:metadata>
	</ui:define>

</ui:composition>